package com.ruoyi.boat.mail;

import com.ruoyi.common.annotation.Log;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.stereotype.Component;


@Component
public class MyMailSender {

    @Autowired
    JavaMailSenderImpl sender;

    @Value("${spring.mail.username}")
    String from;

    /**
     * 发送email
     *
     * @param subject 主题
     * @param text    文本内容
     * @param to      接收者email地址
     */
    public void send(String subject, String text, String to) {
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setSubject(subject);
        simpleMailMessage.setText(text);
        simpleMailMessage.setTo(to);
        simpleMailMessage.setFrom(from);
        sender.send(simpleMailMessage);
    }

}
